<template>
  <div class="full">
    <img class="wave" :src="require('@/assets/img/login/bg.png')" alt="" />

    <div class="login-container">
      <div class="img">
        <img :src="require('@/assets/img/login/illustration.svg')" alt="" />
      </div>

      <div class="login-box">
        <div class="login-form">
          <img class="logo" :src="require('@/assets/img/login/avatar.svg')" alt="" />
          <p class="login-title">KUN CLI TEMP</p>

          <el-form ref="formRef" :model="loginForm" :rules="rules">
            <el-form-item prop="user">
              <el-input v-model="loginForm.user" clearable prefixIcon="User">
              </el-input>
            </el-form-item>
            <el-form-item prop="password">
              <el-input type="password" v-model="loginForm.password" clearable show-password prefixIcon="Lock">
              </el-input>
            </el-form-item>
            <el-button type="primary" class="login-btn" @click="login">登 录</el-button>
          </el-form>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { useStore } from 'vuex'

const loginForm = ref({
  user: 'admin',
  password: 'admin',
  cache: false
})

const rules = ref({
  user: [{ required: true, message: '请输入账号' }],
  password: [{ required: true, message: '请输入密码' }]
})

const formRef = ref()
const store = useStore()
const router = useRouter()

const login = () => {
  formRef.value.validate((valid) => {
    if (valid) {
      store.commit('auth/setToken', new Date().getTime())
      router.push('/home')
    }
  })
}
</script>

<style lang="scss" scoped>
.full {
  position: relative;
}

.wave {
  position: fixed;
  height: 100%;
  width: 80%;
  left: 0;
  bottom: 0;
  z-index: -1;
}

.login-container {
  width: 100vw;
  height: 100vh;
  max-width: 100%;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-gap: 18rem;
  padding: 0 2rem;
}

.img {
  display: flex;
  justify-content: flex-end;
  align-items: center;
}

.login-box {
  display: flex;
  align-items: center;
  text-align: center;
  overflow: hidden;
}

.login-form {
  width: 360px;
}

.login-title {
  color: #aaa;
  font-size: 28px;
  font-weight: bold;
  margin: 20px 0;
}

.logo {
  width: 90px;
  margin: 0 auto;
}

.login-btn {
  width: 100%;
}
</style>
